package com.haixiaoke.saas.enterprise.workOrder.controller;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.workOrder.domain.WorkOrderPwdRecord;
import com.haixiaoke.saas.workOrder.service.IWorkOrderPwdRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工单临时密码申请记录Controller
 *
 * @author qixi
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/enterprise/workOrder/pwd/record")
public class EnterpriseWorkOrderPwdRecordController extends BaseController {
    @Autowired
    private IWorkOrderPwdRecordService workOrderPwdRecordService;

    /**
     * 查询工单临时密码申请记录列表
     */
    @PreAuthorize("@ss.hasPermi('workOrder:pwdRecord:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(WorkOrderPwdRecord workOrderPwdRecord) {
        startPage();
        workOrderPwdRecord.setTenantId(TenantContext.getTenantId());
        List<WorkOrderPwdRecord> list = workOrderPwdRecordService.selectWorkOrderPwdRecordList(workOrderPwdRecord);
        return getDataTable(list);
    }

    /**
     * 导出工单临时密码申请记录列表
     */
    @PreAuthorize("@ss.hasPermi('workOrder:pwdRecord:export')")
    @Log(title = "工单临时密码申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrderPwdRecord workOrderPwdRecord) {
        List<WorkOrderPwdRecord> list = workOrderPwdRecordService.selectWorkOrderPwdRecordList(workOrderPwdRecord);
        ExcelUtil<WorkOrderPwdRecord> util = new ExcelUtil<WorkOrderPwdRecord>(WorkOrderPwdRecord.class);
        util.exportExcel(response, list, "工单临时密码申请记录数据");
    }


    /**
     * 修改工单临时密码申请记录
     */
    @PreAuthorize("@ss.hasPermi('workOrder:pwdRecord:edit')")
    @Log(title = "工单临时密码申请记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderPwdRecord workOrderPwdRecord) {
        return toAjax(workOrderPwdRecordService.updateWorkOrderPwdRecord(workOrderPwdRecord));
    }


    /**
     * 审核工单临时密码申请记录
     */
    @PreAuthorize("@ss.hasPermi('workOrder:pwdRecord:audit')")
    @Log(title = "工单临时密码申请记录", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody WorkOrderPwdRecord workOrderPwdRecord) {
        workOrderPwdRecord.setUpdateBy(getLoginUser().getUsername());
        return toAjax(workOrderPwdRecordService.auditWorkOrderPwdRecord(workOrderPwdRecord));
    }


    /**
     * 查询工单临时密码申请记录列表
     */
    @GetMapping("/countPwdAuditState")
    @TenantScope
    public AjaxResult countPwdAuditState(WorkOrderPwdRecord workOrderPwdRecord) {
        workOrderPwdRecord.setTenantId(TenantContext.getTenantId());
        return success(workOrderPwdRecordService.selectWorkOrderPwdRecordCountPwdAuditState(workOrderPwdRecord));
    }


}
